//
//  CatogryViewController.m
//  project
//
//  Created by lanou on 15/10/26.
//  Copyright © 2015年 lanou. All rights reserved.
//

#import "CatogryViewController.h"
#import "CatogryStrategyViewController.h"
#import "CatogryGiftMainViewController.h"
#import "FMDatabase.h"

@interface CatogryViewController ()

//创建攻略视图控制器
@property(nonatomic,strong)CatogryStrategyViewController *strategyVC;
//创建礼品视图控制器
@property(nonatomic,strong)CatogryGiftMainViewController *giftVC;
//创建一个segmentControl
@property(nonatomic,strong)UISegmentedControl *segmentControl;
//引入数据持久化的类,并写成属性
@property(nonatomic,strong)FMDatabase *dataBase;

@end

@implementation CatogryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _segmentControl = [[UISegmentedControl alloc]initWithItems:@[@"攻略",@"礼品"]];
    _segmentControl.frame = CGRectMake(100, 40, kWidth - 200, 30);
    _segmentControl.selectedSegmentIndex = 0;
    _segmentControl.tintColor = [UIColor whiteColor];
    [_segmentControl addTarget:self action:@selector(doTap:) forControlEvents:(UIControlEventValueChanged)];
    self.navigationItem.titleView = _segmentControl;
    
    _strategyVC = [[CatogryStrategyViewController alloc]init];
    _strategyVC.view.frame = CGRectMake(0, 0, kWidth, kHeight);
    _strategyVC.view.backgroundColor = [UIColor whiteColor];
//    //实现block的方法
    __weak CatogryViewController *newSelf = self;
    _strategyVC.pushSpecial = ^(UIViewController *speCial)
    {
        [newSelf.navigationController pushViewController:speCial animated:YES];
    };
    
    _giftVC = [[CatogryGiftMainViewController alloc]init];
    _giftVC.view.frame = CGRectMake(0, 0, kWidth, kHeight);
    _giftVC.view.backgroundColor = [UIColor whiteColor];
    //实现block方法
    _giftVC.pushGiftItem = ^(UIViewController *giftItemVC)
    {
        [newSelf.navigationController pushViewController:giftItemVC animated:YES];
    };

    
    [self.view addSubview:_giftVC.view];
    [self.view addSubview:_strategyVC.view];
}

-(void)doTap:(UISegmentedControl *)sender
{
    if (sender.selectedSegmentIndex == 0)
    {
        [self.view bringSubviewToFront:_strategyVC.view];
    }
    else
    {
        [self.view bringSubviewToFront:_giftVC.view];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
